<?php

namespace app\admin\controller;

use app\admin\model\SupplierBalanceWarningConfig as SupplierBalanceWarningConfigModel;
use app\admin\validate\SupplierBalanceWarningConfig as SupplierBalanceWarningConfigValidate;

/**
 * 供应商余额预警
 */
class SupplierBalanceWarningConfig extends Controller
{
    public function list()
    {
        $model = new SupplierBalanceWarningConfigModel();
        $data = input('post.');

        return $model->getList($data);
    }

    /**
     * 新增，修改
     */
    public function save()
    {
        $data = input('post.');
        $validate = new SupplierBalanceWarningConfigValidate();
        if (!$validate->scene('create')->check($data)) {
            return fail($validate->getError());
        }

        $model = new SupplierBalanceWarningConfigModel();

        return $model->save($data);
    }

    /**
     * 修改状态
     */
    public function changeStatus()
    {
        $data = input('post.');
        $validate = new SupplierBalanceWarningConfigValidate();
        if (!$validate->scene('changeStatus')->check($data)) {
            return fail($validate->getError());
        }

        $model = new SupplierBalanceWarningConfigModel();

        return $model->changeStatus($data);
    }

    /**
     * 删除.
     */
    public function delete()
    {
        $data = input('post.');
        $model = new SupplierBalanceWarningConfigModel();

        return $model->delete($data);
    }

    /**
     * 供应商列表
     */
    public function getSupplierList()
    {
        $list = SupplierBalanceWarningConfigModel::getSupplierList();
        return success('操作成功', array_values($list));
    }
}
